<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .div1 {
            width: 300px;
            height: 300px;
            background-color: red;
        }
        .div2 {
            width: 200px;
            height: 200px;
            background-color: yellowgreen;
        }
        .div3 {
            width: 100px;
            height: 100px;
            background-color: pink;
        }
    </style>
</head>
<body>
    <div class="div1" onclick="fn1('div1')">
        <div class="div2" onclick="fn1('div2')">
            <div class="div3" onclick="fn1('div3')"></div>
        </div>
    </div>
    <br><br><br><br>
    <div class="div1" oncontextmenu="fn2()">阻止默认事件</div>
    <script>
        function fn1 (name) {
            console.log(name);
            // 阻止冒泡
            let e = event;
            e.cancelBubble = true; // ie
            e.stopPropagation(); // 非ie
        }

        function fn2 () {
            console.log('contextmenu');
            // 阻止默认事件
            var e = event;
            e.preventDefault();
            e.returnValue = false;
        }
    </script>
</body>
</html>